home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / EDITSDI.PAK / DISPATCH.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  173 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   dispatch.c
  9. //
  10. //  PURPOSE:  Implement the generic message and command dispatchers.
  11. //    
  12. //
  13. //  FUNCTIONS:
  14. //    DispMessage - Call the function associated with a message.
  15. //    DispCommand - Call the function associated with a command.
  16. //    DispDefault - Call the appropriate default window procedure.
  17. //
  18. //  COMMENTS:
  19. //
  20.  
  21. #include <windows.h>            // required for all Windows applications
  22. #include <windowsx.h>
  23. #ifdef WIN16
  24. #include "win16ext.h"           // required only for win16 applications
  25. #endif
  26. #include "globals.h"            // prototypes specific to this application
  27.  
  28. LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
  29.  
  30. //
  31. //  FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
  32. //
  33. //  PURPOSE: Call the function associated with a message.
  34. //
  35. //  PARAMETERS:
  36. //    lpmsdi - Structure containing the message dispatch information.
  37. //    hwnd - The window handle
  38. //    uMessage - The message number
  39. //    wparam - Message specific data
  40. //    lparam - Message specific data
  41. //
  42. //  RETURN VALUE:
  43. //    The value returned by the message function that was called.
  44. //
  45. //  COMMENTS:
  46. //    Runs the table of messages stored in lpmsdi->rgmsd searching
  47. //    for a message number that matches uMessage.  If a match is found,
  48. //    call the associated function.  Otherwise, call DispDefault to
  49. //    call the default function, if any, associated with the message
  50. //    structure.  In either case, return the value recieved from the
  51. //    message or default function.
  52. //
  53.  
  54. #pragma argsused
  55. LRESULT DispMessage(LPMSDI lpmsdi,
  56.                     HWND   hwnd, 
  57.                     UINT   uMessage, 
  58.                     WPARAM wparam, 
  59.                     LPARAM lparam)
  60. {
  61.      int  imsd;
  62.  
  63.     MSD *rgmsd = lpmsdi->rgmsd;
  64.     int  cmsd  = lpmsdi->cmsd;
  65.  
  66.     for (imsd = 0; imsd < cmsd; imsd++)
  67.     {
  68.         if (rgmsd[imsd].uMessage == uMessage)
  69.             return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
  70.     }
  71.  
  72.     return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
  73. }
  74.  
  75. //
  76. //  FUNCTION: DispCommand(LPCMDI, HWND, WPARAM, LPARAM)
  77. //
  78. //  PURPOSE: Call the function associated with a command.
  79. //
  80. //  PARAMETERS:
  81. //    lpcmdi - Structure containing the command dispatch information.
  82. //    hwnd - The window handle
  83. //    GET_WM_COMMAND_ID(wparam, lparam) - Identifier of the menu item,
  84. //      control, or accelerator.
  85. //    GET_WM_COMMAND_CMD(wparam, lparam) - Notification code.
  86. //    GET_WM_COMMAND_HWND(wparam, lparam) - The control handle or NULL.
  87. //
  88. //  RETURN VALUE:
  89. //    The value returned by the command function that was called.
  90. //
  91. //  COMMENTS:
  92. //    Runs the table of commands stored in lpcmdi->rgcmd searching
  93. //    for a command number that matches wCommand.  If a match is found,
  94. //    call the associated function.  Otherwise, call DispDefault to
  95. //    call the default function, if any, associated with the command
  96. //    structure.  In either case, return the value recieved from the
  97. //    command or default function.
  98. //
  99.  
  100.  
  101. #pragma argsused
  102. LRESULT DispCommand(LPCMDI lpcmdi, 
  103.                     HWND   hwnd, 
  104.                     WPARAM wparam, 
  105.                     LPARAM lparam)
  106. {
  107.      WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
  108.      int     icmd;
  109.  
  110.     CMD    *rgcmd = lpcmdi->rgcmd;
  111.     int     ccmd  = lpcmdi->ccmd;
  112.  
  113.     // Message packing of wparam and lparam have changed for Win32,
  114.     // so use the GET_WM_COMMAND macro to unpack the commnad
  115.  
  116.     for (icmd = 0; icmd < ccmd; icmd++)
  117.     {
  118.         if (rgcmd[icmd].wCommand == wCommand)
  119.         {
  120.             return rgcmd[icmd].pfncmd(hwnd,
  121.                                       wCommand,
  122.                                       GET_WM_COMMAND_CMD(wparam, lparam),
  123.                                       GET_WM_COMMAND_HWND(wparam, lparam));
  124.         }
  125.     }
  126.  
  127.      return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
  128. }
  129.  
  130.  
  131. //
  132. //  FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
  133. //
  134. //  PURPOSE: Call the appropriate default window procedure.
  135. //
  136. //  PARAMETERS:
  137. //    edwp - Enumerate specifying the appropriate default winow procedure.
  138. //    hwnd - The window handle
  139. //    uMessage - The message number
  140. //    wparam - Message specific data
  141. //    lparam - Message specific data
  142. //
  143. //  RETURN VALUE:
  144. //    If there is a default proc, return the value returned by the
  145. //    default proc.  Otherwise, return 0.
  146. //
  147. //  COMMENTS:
  148. //    Calls the default procedure associated with edwp using the specified
  149. //    parameters.
  150. //
  151.  
  152. LRESULT DispDefault(EDWP   edwp, 
  153.                     HWND   hwnd, 
  154.                     UINT   uMessage, 
  155.                     WPARAM wparam, 
  156.                     LPARAM lparam)
  157. {
  158.     switch (edwp)
  159.     {
  160.         case edwpNone:
  161.             return 0;
  162.         case edwpWindow:
  163.             return DefWindowProc(hwnd, uMessage, wparam, lparam);
  164.         case edwpDialog:
  165.             return DefDlgProc(hwnd, uMessage, wparam, lparam);
  166.         case edwpMDIFrame:
  167.             return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
  168.         case edwpMDIChild:
  169.             return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
  170.     }
  171.     return 0;
  172. }
  173.